fix: soul.md silently truncated to 2000 chars in agent system prompt#672
Merged
yaojin3616 merged 1 commit intoJun 11, 2026
Merged
Conversation
_read_file_safe silently truncates at max_chars (appending "...(truncated)" without logging), and build_agent_context read soul.md with a 2000-char cap. Any agent whose soul.md exceeds 2000 chars therefore ran with every tail section — rules, boundaries, operational facts — silently missing from its system prompt, while the file, DB, and UI all showed the full soul. On one deployment, 68 of 141 agents exceeded the cap (largest 12k chars: only the first 17% ever reached the model), and agents confidently denied facts their souls plainly stated. Soul is author-curated and bounded, so a generous 30000-char cap is safe. Memory and relationships keep their small caps because they grow unbounded at runtime. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
build_agent_context()— the prompt assembler used by chat, heartbeat, A2A and task execution — reads the agent's soul with a 2000-character cap:https://github.com/dataelement/Clawith/blob/30e8b774/backend/app/services/agent_context.py#L253
_read_file_safe(L15–23) silently truncates anything pastmax_chars, appending...(truncated)with no log. So for any agent whosesoul.mdexceeds 2000 chars, everything after char 2000 — rules, boundaries, operational facts — never reaches the model, while the file, the DB and the UI all display the full soul. That makes the failure very hard to diagnose: the agent behaves correctly on the head of its soul and confidently denies facts stated in the tail.Evidence
On one of our deployments, 68 of 141 agents had souls over the cap (largest 12,089 chars — only the first 17% ever reached the model). The symptom that surfaced it: an agent whose soul explicitly lists a service URL kept answering "there is no URL I can share" — the URL section sat at char ~5550 of a 5,927-char soul, past the cut.
Fix
Raise the soul read cap to 30000 at the call site, with a comment explaining the asymmetry: soul is author-curated and bounded (only seeded or explicitly edited), unlike
memory/relationshipswhich grow unbounded at runtime and keep their small caps.One line + comment. Agents with souls ≤2000 chars see a byte-identical prompt — zero behavior change for them.
Verified on a live deployment: after this change,
build_agent_contextstatic prompts for previously-truncated agents contain their full souls (no...(truncated)marker), and the misbehaving agents answer tail-section questions correctly.Possible follow-ups (not in this PR)
_read_file_safewhen truncation actually fires, so silent prompt loss is visible in logs.SOUL_CONTEXT_MAX_CHARS) and add a unit test asserting the soul read uses it while memory keeps its small cap.🤖 Generated with Claude Code